package com.group525.cloudef.controller.doctor;


import com.group525.cloudef.Dao.doctor.DiagnoseDao;
import com.group525.cloudef.Dao.doctor.UserInfo;
import com.group525.cloudef.Dao.doctor.reportRecord;
import com.group525.cloudef.common.CommonResult;
import com.group525.cloudef.entity.doctor.DUser;
import com.group525.cloudef.entity.user.*;
import com.group525.cloudef.service.doctor.DUserService;
import com.group525.cloudef.utils.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author group525
 * @since 2023-04-19
 */
@RestController
@CrossOrigin
@RequestMapping("/doctor/user")
@Api(tags = "医生信息")
public class DUserController {
    @Resource
    DUserService duserService;

    @Resource
    Log log;

    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public CommonResult<?> login(@RequestBody DUser user){
        log.debug("doc",user);
        return duserService.login(user);
    }

    @GetMapping ("/info/{jobNum}")
    @ApiOperation(value = "获取个人信息")
    public UserInfo info(@PathVariable String jobNum){
        return duserService.info(jobNum);
    }

    @PostMapping("/updateInfo")
    @ApiOperation(value = "更新个人信息")
    public CommonResult<?> updateInfo(@RequestBody DUser dUser){
        log.debug("doc:",dUser);
        if (duserService.updateById(dUser)){
            return CommonResult.success("更新成功");
        }
        return CommonResult.failed("更新失败");

    }
    @PostMapping("/uploadAvatar")
    @ApiOperation(value = "上传头像")
    public CommonResult<?> uploadAvatar(@RequestParam("file")MultipartFile file, HttpServletRequest httpServletRequest){
        System.out.println(file.getOriginalFilename());
        return duserService.uploadAvatar(file,httpServletRequest);

    }

    @GetMapping ("/getPatient/{doctor_id}")
    @ApiOperation(value = "获取患者信息")
    public List<DiagnoseDao> getPatient(@PathVariable Long doctor_id){
        return duserService.getPatient(doctor_id);
    }

    @PostMapping("/createInfectious")
    @ApiOperation(value = "提交传染病报告")
    public CommonResult<?> createInfectious(@RequestBody Uinfectious uinfectious){
        log.debug("$$:",uinfectious);
        return duserService.createInfectious(uinfectious);
    }
    @PostMapping("/submitHazard")
    @ApiOperation(value = "提交危急值报告")
    public CommonResult<?> submitHazard(@RequestBody UHazard uHazard){
        log.debug("$$:",uHazard);
        return duserService.submitHazard(uHazard);
    }
    @PostMapping("/submitReport")
    @ApiOperation(value = "提交诊断报告")
    public CommonResult<?> submitReport(@RequestBody UReport uReport){
        log.debug("$$:",uReport);
        return duserService.submitReport(uReport);
    }

    @PostMapping("/reportList")
    @ApiOperation(value = "获取报告列表")
    public List<reportRecord> reportList(){
        return duserService.reportList();
    }
    @PostMapping("/getDiseaseInfo")
    @ApiOperation(value = "获取报告相关信息")
    public UReport getDiseaseInfo(@RequestBody Long reportNo){
        return duserService.getDiseaseInfo(reportNo);
    }
    @PostMapping("/getImage")
    @ApiOperation(value = "获取报告相关影像")
    public List<UImage> getImage(@RequestBody Long reportNo){
        return duserService.getImage(reportNo);
    }
    @PostMapping("/updateReport")
    @ApiOperation(value = "订正诊断报告")
    public CommonResult<?> updateReport(@RequestBody UReport uReport){
        return duserService.updateReport(uReport);
    }

    @PostMapping("/getTitle")
    @ApiOperation(value = "获取通知标题")
    public List<String> getTitle(){
        return duserService.getTitle();
    }

    @GetMapping ("/getContent/{title}")
    @ApiOperation(value = "获取通知内容")
    public String getContent(@PathVariable String title){
        return duserService.getContent(title);
    }
}

